﻿using DotNetty.Handlers.Logging;
using DotNetty.Handlers.Timeout;
using DotNetty.Transport.Channels;
using DotNetty.Transport.Channels.Sockets;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Channels;
using System.Threading.Tasks;
using TestNetty.Client.Handlers;

namespace TestNetty.Client.InitClinet
{
    public class TcpClientInitializer : ChannelInitializer<ISocketChannel>
    {
        protected override void InitChannel(ISocketChannel channel)
        {
            IChannelPipeline pipeline = channel.Pipeline;
            pipeline.AddLast(new LoggingHandler("SRV-CONN"));
            pipeline.AddLast(new IdleStateHandler(30, 30, 60 * 5));//心跳超时
            pipeline.AddLast(new JsonEncoder());//编码器
            pipeline.AddLast(new JsonDecoder());//解码器
            pipeline.AddLast(new ResponseHandler());//消息处理
            pipeline.AddLast(new HeartBeatHandler());//心跳

            
        }
    }
}
